package com.wanlian.netty.File.msg.up;

import com.wanlian.File.NetFileInfo;
import com.wanlian.json.JsonStringUtil;
import com.wanlian.netty.File.model.FileHead;
import com.wanlian.netty.File.msg.FileBaseMsg;
import com.wanlian.netty.msg.MsgType;

/**
 * 文件头
 */
public class FilePeerUpHeadMsg extends FileBaseMsg {
    private FileHead head;

    public FilePeerUpHeadMsg() {
        this.setType(MsgType.DEVICE_FILE_UPLOAD_HEAD);
    }

    public FileHead getHead() {
        return head;
    }

    public void setHead(FileHead head) {
        this.head = head;
        this.setContent(JsonStringUtil.writeValueAsString(head));
    }

    public void setHead(NetFileInfo netFileInfo){
        this.setType(MsgType.DEVICE_FILE_UPLOAD_HEAD);
        this.head = new FileHead();
        this.head.setSize(netFileInfo.getSize());
        this.head.setFileName(netFileInfo.getFileName());
        this.head.setOffset(netFileInfo.getCurrentIndex());
        this.head.setTotal(netFileInfo.getTotalSize());
        this.head.setFileType(1);
        this.getBaseHead().setClientId("aaaa");
        this.getBaseHead().setTagClientId("7a24e88976a9215f8ef76d6a6a4353a4");
        this.setContent(JsonStringUtil.writeValueAsString(this.head));
        this.setData(netFileInfo.getBytes());
    }
}
